package org.zch.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zch.common.ApiResult;
import org.zch.service.AdminService;
import org.zch.service.ZuoRuiService;

/**
 * 焯瑞开关
 *
 * @author 赵昌虎
 */
@RestController
@RequestMapping("/zuorui")
@Api(tags = "焯瑞无线开关")
public class ZuoRuiOpenController {

    @Autowired
    private ZuoRuiService zuoRuiService;

    /**
     * 新增设备
     */
    @ApiOperation(value = "新增设备", notes = "新增设备")
    @PostMapping("/addZuoRui")
    public ApiResult addZuoRui(@RequestParam("ip8266") String ip8266,@RequestParam("status") String status) {
        return ApiResult.ok(zuoRuiService.addZuoRui(ip8266,status));
    }

    /**
     * 修改开关状态
     */
    @ApiOperation(value = "修改开关状态", notes = "修改开关状态")
    @PostMapping("/upZuoRuiStatus")
    public ApiResult upZuoRuiStatus(@RequestParam("ip8266") String ip8266,@RequestParam("status") String status) {
        return ApiResult.ok(zuoRuiService.upZuoRuiStatus(ip8266,status));
    }

    /**
     * 修改紧急状态
     */
    @ApiOperation(value = "修改紧急状态", notes = "修改紧急状态")
    @PostMapping("/upZuoRuiDanger")
    public ApiResult upZuoRuiDanger(@RequestParam("ip8266") String ip8266,@RequestParam("danger") String danger) {
        return ApiResult.ok(zuoRuiService.upZuoRuiDanger(ip8266,danger));
    }


    /**
     * 修改紧急状态
     */
    @ApiOperation(value = "修改定时", notes = "修改定时")
    @PostMapping("/upZuoRuiTime")
    public ApiResult upZuoRuiTime(@RequestParam("ip8266") String ip8266, @RequestParam("timeRepeat") String timeRepeat, @RequestParam("timeOpen") String timeOpen, @RequestParam("timeClose") String timeClose) {
        return ApiResult.ok(zuoRuiService.upZuoRuiTime(ip8266,timeRepeat,timeOpen,timeClose));
    }

    /**
     * 获取开关状态
     */
    @ApiOperation(value = "获取开关状态", notes = "获取开关状态")
    @PostMapping("/getZuoRuiStatus")
    public ApiResult getZuoRuiStatus(@RequestParam("ip8266") String ip8266) {
        return ApiResult.ok(zuoRuiService.getZuoRuiStatus(ip8266));
    }


    /**
     * 获取开关信息
     */
    @ApiOperation(value = "获取开关信息", notes = "获取开关信息")
    @PostMapping("/getZuoRui")
    public ApiResult getZuoRui(@RequestParam("ip8266") String ip8266) {
        return ApiResult.ok(zuoRuiService.getZuoRui(ip8266));
    }


    /**
     * 更新上次登录时间
     */
    @ApiOperation(value = "更新上次登录时间", notes = "更新上次登录时间")
    @PostMapping("/upLastTime")
    public ApiResult deleteAdmin(@RequestParam("ip8266") String ip8266) {
        return ApiResult.ok(zuoRuiService.upLastTime(ip8266));
    }


    /**
     * 查询所有开关
     */
    @ApiOperation(value = "查询所有开关", notes = "查询所有开关")
    @PostMapping("/findAll")
    public ApiResult findAll() {
        return ApiResult.ok(zuoRuiService.findAll());
    }

}
